# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=dumb
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.9.3
pkgrel=5
pkgdesc="IT, XM, S3M and MOD player library (mingw-w64)"
arch=('any')
url="https://dumb.sourceforge.io/"
license=("custom:dumb, GPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
options=('strip' 'staticlibs')
source=("https://downloads.sourceforge.net/sourceforge/dumb/dumb-${pkgver}.tar.gz"
        "CVE-2006-3668.patch"
        "config.txt")
sha256sums=('8d44fbc9e57f3bac9f761c3b12ce102d47d717f0dd846657fb988e0bb5d1ea33'
            '9f6785435757db725bc73b1c4874b91e80b9277c6fdd2b56e47dae1cfbc968e6'
            '5319fd08ad12bce4fc3ec41cbeeb71a40041867c56a713d564920f32e0ff4aa2')

prepare() {
  cd "${srcdir}/dumb-${pkgver}"
  patch -p1 -i ${srcdir}/CVE-2006-3668.patch
  cp ${srcdir}/config.txt make/
}

build() {
  cd "${srcdir}/dumb-${pkgver}"
  sed -i "s,PKGDIR/usr/ARCH,${pkgdir}${MINGW_PREFIX}," "make/config.txt"
  COMSPEC=/usr/bin/sh.exe make CC=${MINGW_CHOST}-gcc AR=ar RANLIB=ranlib
  ${MINGW_CHOST}-gcc -shared obj/unix/release/*.o -o libdumb.dll -Xlinker --out-implib -Xlinker libdumb.dll.a
}

package() {
  cd "${srcdir}/dumb-${pkgver}"
  mkdir -p "${pkgdir}${MINGW_PREFIX}/"{bin,include,lib}
  COMSPEC=/bin/sh.exe make PREFIX=${pkgdir}${MINGW_PREFIX} install
  rm "${pkgdir}${MINGW_PREFIX}/lib/libdumbd.a"
  install -m644 "libdumb.dll" "${pkgdir}${MINGW_PREFIX}/bin/"
  install -m644 "libdumb.dll.a" "${pkgdir}${MINGW_PREFIX}/lib/"
}
